package com.neusoft.elmboot.controller;

import java.util.List;

import com.neusoft.elmboot.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Options;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.neusoft.elmboot.po.Orders;
import com.neusoft.elmboot.service.OrdersService;

/**
 * 订单
 * Controller
 */
@Slf4j
@RestController
@RequestMapping(value = "/OrdersController")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 创建订单
     * @param orders
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/createOrders")
    public Result<Integer> createOrders(Orders orders) throws Exception{
        log.info("调用接口：创建订单");
        return Result.success(ordersService.createOrders(orders));
    }

    /**
     * 根据ID查询订单
     * @param orders
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getOrdersById")
    public Result<Orders> getOrdersById(Orders orders) throws Exception{
        log.info("调用接口：根据ID查询订单");
        return Result.success(ordersService.getOrdersById(orders.getOrderId()));
    }

    /**
     * 根据用户ID列出订单
     * @param orders
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/listOrdersByUserId")
    public Result<List<Orders>> listOrdersByUserId(Orders orders) throws Exception{
        log.info("调用接口：根据用户ID列出订单");
        return Result.success(ordersService.listOrdersByUserId(orders.getUserId()));
    }

    /**
     * 完成订单支付
     * @param orders
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateOrderState")
    public Result updateOrderState(Orders orders) throws Exception{
        ordersService.updateOrderState(orders.getOrderId());
        log.info("调用接口：完成订单支付");
        return Result.success();
    }

    /**
     * 逻辑删除未支付订单
     * @param orders
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deleteOrder")
    public Result deleteOrder(Orders orders) throws Exception{
        ordersService.deleteOrder(orders.getOrderId());
        log.info("调用接口：删除未支付订单");
        return Result.success();
    }
}